package logic

import (
	"api/internal/svc"
	"api/internal/types"
	"context"
	"rpc/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddOrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOrderLogic {
	return &AddOrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddOrderLogic) AddOrder(req *types.AddOrderRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	addOrder, err := l.svcCtx.OrderRpc.AddOrder(l.ctx, &order.AddOrderRequest{
		UserId:  int64(req.UserId),
		GoodsId: int64(req.GoodsId),
		PayType: int64(req.PayType),
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  "下单失败" + err.Error(),
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "下单成功",
		Data: map[string]interface{}{
			"addOrder": addOrder.Url,
		},
	}, nil
}
